﻿using System;
using System.Collections.Generic;
using System.Text;
using DreamShield.Deployment.Assistants.DreamWizard;
using DreamShield.Deployment.Installers.DreamWorker;

namespace DreamShield.Deployment.Miles.Events
{
    /// <summary>
    /// Fournit les évènements à la foi pour le wizard minimaliste et le wizard
    /// standard. Basé sur <see cref="EventsProvider_MiniWizard"/> et <see cref="EventsProvider_StandardWizard"/>
    /// </summary>
    public class EventsProvider_GeneralWizard : BaseMilesPlugin
    {
        /// <summary>
        /// Gestionnaire pour le standard
        /// </summary>
        protected virtual EventsProvider_StdWizard StandardHandler { get; set; }

        /// <summary>
        /// Gestionnaire pour le minimaliste
        /// </summary>
        protected virtual EventsProvider_MiniWizard MinimalistHandler { get; set; }

        /// <summary>
        /// Crée une nouvelle instance de la classe EventsProvider_GeneralWizard
        /// </summary>
        /// <param name="server">Serveur Miles en cours</param>
        public EventsProvider_GeneralWizard(MilesRootServer server)
            : base(server)
        {
            StandardHandler = new EventsProvider_StdWizard(server);
            MinimalistHandler = new EventsProvider_MiniWizard(server);

            StandardHandler.WizardWorkerExecute_BeginEvent += new EventsProvider_StdWizard.WizardWorker_Event(WizardWorkerExecute_Begin);
            StandardHandler.WizardWorkerExecute_EndEvent += new EventsProvider_StdWizard.WizardWorker_Event(WizardWorkerExecute_End);

            MinimalistHandler.WizardWorkerExecute_BeginEvent += new EventsProvider_MiniWizard.WizardWorker_Event(WizardWorkerExecute_Begin);
            MinimalistHandler.WizardWorkerExecute_EndEvent += new EventsProvider_MiniWizard.WizardWorker_Event(WizardWorkerExecute_End);
        }

        /// <summary>
        /// Evènement lors d'une action de l'assistant standard
        /// </summary>
        /// <param name="engine">Engine actuel</param>
        /// <param name="actionId">Action effectuée par l'assistant</param>
        public delegate void WizardWorker_Event(DreamWizardEngine engine, WorkerActionId actionId);

        /// <summary>
        /// Appelé avant le début de l'exécution de l'assistant
        /// </summary>
        public event WizardWorker_Event WizardWorkerExecute_BeginEvent;

        /// <summary>
        /// Appelé après l'exécution de l'assistant
        /// </summary>
        public event WizardWorker_Event WizardWorkerExecute_EndEvent;

        /// <summary>
        /// Déclanche l'évènement WizardWorkerExecute_BeginEvent
        /// </summary>
        /// <param name="engine">Engine actuel</param>
        /// <param name="actionId">Action effectuée par l'assistant</param>
        protected virtual void WizardWorkerExecute_Begin(DreamWizardEngine engine, WorkerActionId actionId)
        {
            if (WizardWorkerExecute_BeginEvent != null)
                WizardWorkerExecute_BeginEvent(engine, actionId);
        }

        /// <summary>
        /// Déclanche l'évènement WizardWorkerExecute_EndEvent
        /// </summary>
        /// <param name="engine">Engine actuel</param>
        /// <param name="actionId">Action effectuée par l'assistant</param>
        protected virtual void WizardWorkerExecute_End(DreamWizardEngine engine, WorkerActionId actionId)
        {
            if (WizardWorkerExecute_EndEvent != null)
                WizardWorkerExecute_EndEvent(engine, actionId);
        }
    }
}
